package com.android.dopewars;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class DealerEdit extends Activity {
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.edit_dealer);
        ((EditText)findViewById(R.id.dealer_name)).setText(Global.dealer_.name());
        ((RadioButton)findViewById(R.id.dealer_gender_is_male)).setChecked(
        		Global.dealer_.gender_is_male());
        ((RadioButton)findViewById(R.id.dealer_gender_is_female)).setChecked(
        		!Global.dealer_.gender_is_male());
        ((Button)findViewById(R.id.submit_dealer)).setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		Global.dealer_.setName(((EditText)findViewById(R.id.dealer_name)).getText().toString());
        		Global.dealer_.setGenderIsMale(((RadioButton)findViewById(R.id.dealer_gender_is_male)).isChecked());
        		Intent i = new Intent();
        		setResult(RESULT_OK, i);
        		finish();
        	}
        });
        
        ((Button)findViewById(R.id.delete_dealer)).setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		Global.dealers_.remove(Global.dealer_);
        		if(Global.dealers_.size() > 0) {
        			Global.dealer_ = Global.dealers_.elementAt(0);
        		} else {
        			Global.dealer_ = null;
        		}
        		Intent i = new Intent();
        		setResult(RESULT_OK, i);
        		finish();
        	}
        });
        
        WindowManager.LayoutParams dialog_params = getWindow().getAttributes();
    	dialog_params.width = WindowManager.LayoutParams.FILL_PARENT;
    	getWindow().setAttributes(dialog_params);
    }
}
